package com.android.djlmapp.activity.kaika;

import android.content.Intent;

import com.android.djlmapp.http.GlobalUrls;
import com.android.djlmapp.model.kaika.SelectNumInfo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @Author wangziheng
 * @ProjectName djlm
 * @ClassName SelectNumChildActivity
 * @package com.android.djlmapp.activity.kaika
 * @data 2019/1/31 16:21
 * @Describe
 * @Change
 */
public class SelectNumChildActivity extends SelectNumActivity {
    /**
     * 其他界面传递过来的参数(目前是json字符串)的key值
     */
    public static final String REQUEST_PARAMS_KEY = "REQUEST_PARAMS_KEY";
    /**
     * 回传过去的手机号码的key值
     */
    public static final String SELECTED_TEL_KEY = "SELECTED_TEL_KEY";
    @Override
    protected void initView() {
        String stringJson = getIntent().getStringExtra(REQUEST_PARAMS_KEY);
        try {
            JSONObject jsonObject = new JSONObject(stringJson);
            JSONArray jsonArray = jsonObject.optJSONArray("data");
            PAGE_DATA_URL = GlobalUrls.MAIN_URL + jsonObject.optString("url");
            if(jsonArray != null && jsonArray.length() > 0){
                for(int index = 0 ; index < jsonArray.length() ; index ++){
                    JSONObject paramsObject = jsonArray.optJSONObject(index);
                    String key = paramsObject.optString("key");
                    String value = paramsObject.optString("value");
                    mOtherParams.put(key,value);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
            showToast("服务端数据异常，请重试");
            finish();
        }
        super.initView();
    }

    @Override
    public void selectedNum(SelectNumInfo.PhoneList item) {
        String phoneNum = item.getPhonenum();
        Intent intent = getIntent();
        intent.putExtra(SELECTED_TEL_KEY,phoneNum);
        setResult(RESULT_OK,intent);
        finish();
    }
}
